import { _decorator, Component, easing, Node, Sprite, tween, UITransform, Vec3 } from 'cc';
import { Global } from './Global';

const { ccclass, property } = _decorator;

@ccclass('ProgressAction')
export class ProgressAction extends Component {
    @property({type:Node})
    level_progress:Node
    @property({type:Node})
    particle:Node
    start() {
    }

    dt:number = 0;
    data_temp:number = 0;
    update(deltaTime: number) {
        this.dt+=deltaTime;
        if(this.dt<1){
            return;
        }
        let data = Global.cur_lvl_pin_move_num/Global.cur_lvl_pin_total;
        if(this.data_temp == data){
            return;
        }
        this.data_temp = data;

      
        // console.log("data>>",data);
        let width = this.level_progress.getComponent(UITransform).contentSize.width; 
        let add = width*data;

        // this.particle.setPosition(width/2*-1+add,0);
        tween(this.particle).to(0.5,{position:new Vec3(width/2*-1+add,0)},{ easing: 'quadInOut' }).call(()=>{
            // this.level_progress.getComponent(Sprite).fillRange = data;

            tween(this.level_progress.getComponent(Sprite)).to(0.3,{fillRange:data},{ easing: 'quadInOut' }).start();
        }).start();
    }
}

